<script>
	// #ifdef APP-PLUS
	import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
	// #endif
	import * as db from '@/common/db.js'
	
	import * as Api from '@/common/Api.js'
	
	// #ifdef APP-PLUS || H5
	import { TUIChatKit, genTestUserSig } from "./TUIKit";
	import { vueVersion } from "./TUIKit/adapter-vue";
	import { TUILogin } from "@tencentcloud/tui-core";
	// #endif
	
	// 必填信息
	const config = {
	  userID: db.get('userInfo').membe_id, //User ID
	  SDKAppID: 1400829605, // Your SDKAppID
	  secretKey: "0d36ea5341e6a7f7eb5871b80a7003561bfa054c6b0e970033e64d599cac7223", // Your secretKey
	};
	uni.$chat_userID = config.userID;
	uni.$chat_SDKAppID = config.SDKAppID;
	uni.$chat_secretKey = config.secretKey;
	
	// #ifdef APP-PLUS || H5
	uni.$chat_userSig = genTestUserSig(config).userSig;
	// TUIChatKit 初始化
	
	if(db.get('userInfo').membe_id){
		TUIChatKit.init();
	}
	
	// #endif
	
	
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				data: null,
				t_id:0,
			}
		},
		mounted() {
			/**官网有很多关于关于sdk 其他的监听方法（比如：有新的消息，用户资料更新等等）
			 * 详情可对照： https://imsdk-1252463788.file.myqcloud.com/IM_DOC/Web/SDK.html
			 * 监听的含义：服务端发生了数据变更---前端全局可以接收到变更通知--前端就可以自动触发某个事件来更新相应数据
			 * */


			// 登录成功后会触发 SDK_READY 事件，该事件触发后，可正常使用 SDK 接口
			// this.tim.on(this.$TIM.EVENT.SDK_READY, this.onReadyStateUpdate, this);

			// 收到新消息
			// this.tim.on(this.$TIM.EVENT.MESSAGE_RECEIVED, this.onReceiveMessage);

			// 会话列表更新
			// this.tim.on(this.$TIM.EVENT.CONVERSATION_LIST_UPDATED, event => {
			// 	this.$store.commit("updateConversationList", event.data);
			// });

			// 好友列表更新
			// this.tim.on(this.$TIM.EVENT.FRIEND_LIST_UPDATED, event => {
			// 	this.$store.commit("updateFriendList", event.data);
			// });
		},
		computed: {
			...mapState({
				isLogin: state => state.isLogin,
				isSDKReady: state => state.isSDKReady,
			})
		},
		methods: {
			getOrder(){
				Api.default.request('order/orderList1', {
					status: '',
					type: 1,
					page: 1,
					like: ''
				}, 'POST', false).then((res) => {
					if (res.code) {
						let orderList = res.data.data || []
						
						return orderList
					}
				})
			},
			
			getIMchat(){
				// 必填信息
				const config = {
				  userID: db.get('userInfo').membe_id, //User ID
				  SDKAppID: 1400829605, // Your SDKAppID
				  secretKey: "0d36ea5341e6a7f7eb5871b80a7003561bfa054c6b0e970033e64d599cac7223", // Your secretKey
				};
				uni.$chat_userID = config.userID;
				uni.$chat_SDKAppID = config.SDKAppID;
				uni.$chat_secretKey = config.secretKey;
				
				// #ifdef APP-PLUS || H5
				uni.$chat_userSig = genTestUserSig(config).userSig;
				// TUIChatKit 初始化
				
				if(db.get('userInfo').membe_id){
					TUIChatKit.init();
				}
				
				// #endif
				
				// #ifdef APP-PLUS || H5
				// TUICore login
				if(db.get('userInfo').membe_id){
					TUILogin.login({
					  SDKAppID: uni.$chat_SDKAppID,
					  userID: uni.$chat_userID,
					  // UserSig 是用户登录即时通信 IM 的密码，其本质是对 UserID 等信息加密后得到的密文。
					  // 该方法仅适合本地跑通 Demo 和功能调试，详情请参见 https://cloud.tencent.com/document/product/269/32688     
					  userSig: uni.$chat_userSig, 
					  // 如果您需要发送图片、语音、视频、文件等富媒体消息，请设置为 true
					  useUploadPlugin: true,
					  // 本地审核可识别、处理不安全、不适宜的内容，为您的产品体验和业务安全保驾护航
					  // 此功能为增值服务，请参考：https://cloud.tencent.com/document/product/269/79139
					  // 如果您已购买内容审核服务，开启此功能请设置为 true
					  useProfanityFilterPlugin: false,
					  // framework: `vue${vueVersion}` // 当前开发使用框架 vue2 / vue3
					  framework: 'vue2' // 当前开发使用框架 vue2 / vue3
					});
				}
				 // #endif
			},
			onReadyStateUpdate({
				name
			}) {
				const isSDKReady = name === this.$TIM.EVENT.SDK_READY ? true : false;
				//自动监听并更新 sdk 的ready 状态 （未登录是 notReady  登录后是ready）
				this.$store.commit("toggleIsSDKReady", isSDKReady);
				//sdk ready 后  肯定完成了登录操作    这里可以获取用户存储在im的基础信息/离线消息/黑名单列表
			},

			onReceiveMessage({
				data: messageList
			}) {
				// this.handleAt(messageList);
				this.$store.commit("pushCurrentMessageList", messageList);
				this.imNum = this.tim.getTotalUnreadMessageCount()
			},
			//根据消息列表请求聊天对象的用户信息 并完成数据拼接

		},
		onLaunch: function() {
		
			
			
			// #ifdef APP-PLUS
			
						uni.onPushMessage((res)=>{
							console.log(res,777777)
							let payload = res.data.payload;
								   if(payload.path && payload.path !=""){
									   
									   uni.navigateTo({
										url: payload.path
									   })
								   }
							// uni.createPushMessage({
							//    title: res.data.title,
							//    content: res.data.content,
							//    payload: payload,
							//    sound:"system",
							//    success: (res) => {
							// 	   //payload
							// 	   if(payload.path && payload.path !=""){
									   
							// 		   uni.navigateTo({
							// 			url: payload.path
							// 		   })
							// 	   }
							//    },
							//    fail: (err) => {
							// 	 console.log("自创推送失败",err)
							//    }
							//  })
					})
			// #endif
			
			// 是否显示自定义隐私弹窗
			// uni.setStorageSync("is_looks",1);
			
			console.log('App Launch')
			uni.setStorageSync("end_path","/pages/index/index");

			// #ifdef APP-PLUS
			APPUpdate();
			// #endif
			
			// #ifdef APP-PLUS || H5
			// TUICore login
			if(db.get('userInfo').membe_id){
				TUILogin.login({
				  SDKAppID: uni.$chat_SDKAppID,
				  userID: uni.$chat_userID,
				  // UserSig 是用户登录即时通信 IM 的密码，其本质是对 UserID 等信息加密后得到的密文。
				  // 该方法仅适合本地跑通 Demo 和功能调试，详情请参见 https://cloud.tencent.com/document/product/269/32688     
				  userSig: uni.$chat_userSig, 
				  // 如果您需要发送图片、语音、视频、文件等富媒体消息，请设置为 true
				  useUploadPlugin: true,
				  // 本地审核可识别、处理不安全、不适宜的内容，为您的产品体验和业务安全保驾护航
				  // 此功能为增值服务，请参考：https://cloud.tencent.com/document/product/269/79139
				  // 如果您已购买内容审核服务，开启此功能请设置为 true
				  useProfanityFilterPlugin: false,
				  // framework: `vue${vueVersion}` // 当前开发使用框架 vue2 / vue3
				  framework: 'vue2' // 当前开发使用框架 vue2 / vue3
				});
			}
			 // #endif
			
			// if(uni.getStorageSync("isLaunch")){
			// 	uni.reLaunch({
			// 		url: '/pages/index/index'
			// 	})
			// }
		},
		onShow: function() {
			console.log(1111111)
			
			// uni.getPushClientId({
			//     success: (res) => {  
			//       let push_clientid = res.cid  
			//       console.log('客户端推送标识cid1111111111111:',push_clientid)  
			//     },  
			//     fail(err) {  
			//       console.log(err)  
			//     }  
			//   })
			   let that = this;
			  // #ifdef APP
			  	uni.getPushClientId({
			  	   success: (res) => {  
			  		// that
			  		 console.log('客户端推送标识cid:',res.cid)  
		
						 if(db.get('userInfo').membe_id){
								
								// console.log(db.get('userInfo').membe_id,7777777777);
								that.$api.default.request('user/userlis', {t_id:res.cid},'POST', true,{token:that.token}).then((res) => {
										 console.log('客户端推送标识cid:11',res)  
								})
						 }
			  	   },  
			  	   fail(err) {  
			  		 console.log(err)  
			  	   }  
			  	 })
			  // #endif
			  
			if(db.get('userInfo').membe_id){
				
			
					// console.log(db.get('userInfo').membe_id,7777777777);
					this.$api.default.request('user/userli', {membe_id:db.get('userInfo').membe_id,type:1},'POST', true,{token:this.token}).then((res) => {
						
					})
		
			}
			console.log('App Show')
			// this.$store.commit('reset')
		},
		onHide: function() {
			if(db.get('userInfo').membe_id){
				this.$api.default.request('user/userli', {membe_id:db.get('userInfo').membe_id,type:0},'POST', true,{token:this.token}).then((res) => {
					
				})
			}
			
			console.log('App Hide') 
		}

	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	@import "static/css/main.css";
	@import '@/common/zwyCss.css';

	[v-cloak] {
		display: none !important;
	}

	.content {
		padding-bottom: 170rpx !important;
	}
	
		checkbox .uni-checkbox-input{
			border-radius: 50px !important;
			border-color: #45C4B0 !important;
			/* background-color: #45C4B0 !important; */
			color: #45C4B0 !important;
		}


	/*每个页面公共css */
	button {
		position: relative;
		display: block;
		margin: 0 !important;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		text-align: center;
		text-decoration: none;
		line-height: 1.35;
		background: transparent !important;
		-webkit-tap-highlight-color: transparent !important;
		overflow: hidden;
		color: #000000;
		background-color: #fff;
		border: none !important;
	}

	button::after {
		border: none;
	}

	checkbox .wx-checkbox-input {
		width: 40rpx;
		height: 40rpx;
		border-radius: 50% !important;
		color: #ffffff !important;
	}

	checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		color: #fff;
		background: #45C4B0;
		font-size: 12rpx !important;
	}

	.oneline {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		word-wrap: break-word;
	}

	.twolines {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.threelines {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		overflow: hidden;
	}

	.lines {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	::-webkit-scrollbar {
		border: none !important;
	}

	.u-popup__content {
		background-color: transparent !important;
	}

	.empytView {
		width: 100%;
		padding: 40rpx 0;
		text-align: center;
	}

	.empytView image {
		width: 250rpx;
		height: 250rpx;
	}

	.empytView view {
		color: #c3c3c3;
		padding-bottom: 40rpx;
	}

	.nomore {
		padding: 10rpx 0 20rpx 0;
		text-align: center;
		color: #c3c3c3;
	}



	// 支付弹窗样式
	.fubox {
		background-color: #ffffff;
		border-top-left-radius: 8px;
		border-top-right-radius: 8px;
		padding: 40rpx 0 0;

		.futitle {
			font-size: 28rpx;
			font-weight: bold;
			letter-spacing: 0em;
			text-align: center;
			color: #3D3D3D;
			padding-bottom: 40rpx;
		}

		.bititle {
			font-size: 28rpx;
			font-weight: bold;
			letter-spacing: 0em;
			text-align: center;
			color: #3D3D3D;
			padding-bottom: 20rpx;
		}

		.lbai {
			padding: 0 25rpx 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.lpic {
				width: 42rpx;
				height: 42rpx;
			}

			.ltxt {
				flex-grow: 1;
				font-size: 28rpx;
				color: #3D3D3D;
				padding: 0 12rpx;

				text {
					font-size: 20rpx;
					padding-left: 5rpx;
					color: #999999;
				}
			}
		}

		.lizhi {
			height: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-top: 20rpx solid #f2f5f2;

			.quezhi {
				width: 630rpx;
				height: 80rpx;
				text-align: center;
				line-height: 80rpx;
				border-radius: 8px;
				background: #45C4B0;
				font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
		}

		.jinbox {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding-left: 20rpx;

			.jinli:nth-child(3n) {
				margin-right: 0;
			}

			.jinli {
				width: 220rpx;
				height: 72rpx;
				border-radius: 4px;
				box-sizing: border-box;
				border: 1px solid #D8D8D8;
				margin: 0 16rpx 12rpx 0;
				position: relative;

				.jintop {
					padding-top: 6rpx;
					display: flex;
					align-items: center;
					justify-content: center;

					.jintxt {
						font-size: 24rpx;
						font-weight: bold;
						color: #3D3D3D;
						padding-right: 7rpx;
					}

					.jinpic {
						width: 20rpx;
						height: 20rpx;
					}
				}

				.yuan {
					font-size: 20rpx;
					text-align: center;
					color: #999999;
				}

				.jiao {
					position: absolute;
					bottom: 0;
					right: 0;
					width: 40rpx;
					height: 40rpx;
					z-index: 10;
				}

				.duih {
					position: absolute;
					right: 1rpx;
					bottom: 1rpx;
					width: 24rpx;
					height: 24rpx;
					z-index: 22;
				}
			}

			.jactive {
				border: 1px solid #45C4B0;
			}
		}

		.shubox {
			margin: 10rpx 25rpx 20rpx;
			padding: 0 10rpx;
			height: 72rpx;
			border-radius: 8px;
			background: #F8F8F8;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.shutitle {
				font-size: 28rpx;
				font-weight: normal;
				letter-spacing: 0em;
				color: #3D3D3D;
			}

			.shuput {
				padding: 0 10rpx;
				font-size: 24rpx;
				flex: 1;
				text-align: right;
				letter-spacing: 0em;
				color: #3D3D3D;
			}
		}
	}

	// 10.16新增
	.display-flex {
		display: flex;
		align-items: center;
	}

	.just-between {
		justify-content: space-between;
	}

	.mr10 {
		margin-right: 10rpx;
	}
	
	// .u-safe-area-inset-bottom{
	// 	background-color: #fff;
	// }
	
	.full-page{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100vh;
		background-color: #fff;
		z-index: 999;
	}
	
	.ip{
		padding-left: 8px;
		font-size: 20rpx;
		color: #999;
	}
	
	.pusher{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 40px;
		height: 16px;
		border-radius: 4px;
		background: rgba(69, 196, 176, 0.15);
		font-size: 10px;
		color: #45C4B0;
		margin-left: 15rpx;
	}
	
	/deep/.uni-tabbar{
		box-shadow: 0 0 3px #eeeeee;
	}
	
	// .uni-page-head__title{
	// 	font-size: 14px!important;
	// 	font-weight: bold!important;
	// }
	
	.pop-login{
		width: 100%;
		height: 100vh;
		background-color: #fff;
		flex-direction: column;
		// justify-content: center;
		position: relative;
		padding-top: 80px;
		box-sizing: border-box;
		
		.pop-close{
			width: 100%;
			padding: 0 30rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: flex-start;
			margin-bottom: 97px;
			
			image{
				width: 24px;
				height: 24px;
			}
		}
		
		.pop-title{
			font-family: 思源黑体;
			font-size: 12px;
			color: #3D3D3D;
		}
		
		.pop-logo{
			margin-top: 20px;
			margin-bottom: 42px;
			width: 80px;
			height: 80px;
		}
		
		.pop-btn{
			width: 630rpx;
			height: 86rpx;
			border-radius: 8px;
			line-height: 86rpx;
			margin: 0 auto 20rpx;
			opacity: 1;
			background: #45C4B0;
			font-size: 32rpx;
			font-weight: bold;
			letter-spacing: 0em;
			text-align: center;
			color: #FFFFFF;
			border: 1px solid #45C4B0;
		}
		
		.xiebox {
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 10rpx;
		
			.xietxt {
				font-size: 24rpx;
				color: #999999;
		
				text {
					font-size: 24rpx;
					font-weight: bold;
					color: #45C4B0;
					padding: 0 10rpx;
				}
			}
		}
	}
	
	.custom-bot-pay {
		text-align: center;
		background-color: #fff;
		border-radius: 8px 8px 0 0;
		
		.title{
			padding: 20px 0;
			font-family: '思源黑体';
			font-size: 14px;
			font-weight: bold;
			color: #3D3D3D;
		}
	
		.pay-item{
			padding: 10px 25px;
			padding-bottom: 15px;
			font-family: 思源黑体;
			font-size: 14px;
			color: #3D3D3D;
			position: relative;
			
			.icon{
				width: 16px;
				height: 16px;
				margin-right: 8px;
			}
			
			.sel{
				position: absolute;
				right: 25px;
				top: 50%;
				transform: translateY(-50%);
				width: 20px;
				height: 20px;
			}
		}
		
		.marginBorder{
			width: 100%;
			height: 10px;
			background: #F2F5F2;
		}
		
		.btn{
			margin: 10px auto;
			width: 315px;
			height: 40px;
			line-height: 40px;
			border-radius: 8px;
			background: #45C4B0;
			font-family: '思源黑体';
			font-size: 16px;
			font-weight: bold;
			color: #FFFFFF;
		}
		
		.xietxt {
			margin-top: 10px;
			font-size: 20rpx;
			font-weight: bold;
			color: #999999;
			padding-bottom: 10px;
		
			text {
				font-size: 20rpx;
				font-weight: bold;
				color: #45C4B0;
				padding: 0 10rpx;
			}
		}
	}
</style>